package com.kpijavatraining6.module2.sessionTools;

import com.kpijavatraining6.module2.actionTools.TestStep;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: user
 * Date: 14.11.13
 * Time: 17:00
 * To change this template use File | Settings | File Templates.
 */

public class LevelChecker {
    private static int questionLevel = 2;

    private final double GRATE_RESULT = 1.0;
    private final double BAD_RESULT = 0.8;

    public int check(ArrayList<TestStep> testSteps){
        int counter = 0;
        for(TestStep testStep : testSteps){
            if(testStep.isRightAnswer()){
                counter++;
            }
        }
        return checkCondition(counter, testSteps.size());
    }

    private int checkCondition(int counter, int arraySize){
        if(counter >= arraySize*GRATE_RESULT){
            if(questionLevel != 3){
                return questionLevel++;
            }
        }else if(counter <= arraySize*BAD_RESULT){
            if(questionLevel != 1){
                return questionLevel--;
            }
        }
        return questionLevel;
    }
}
